<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let cache = {};
      function fib(n) {
        debugger;
        if (n === 1 || n === 0) {
          return 1;
        }
        if (cache[n]) {
          return cache[n];
        }
        let result = fib(n - 1) + fib(n - 2);
        cache[n] = result;
        return result;
      }
      console.log(fib(4));
    </script>
  </body>
</html>
